package uk.ac.aber.Blockmation.Actions;

import java.awt.event.ActionEvent;

import java.io.File;
import javax.swing.AbstractAction;

import uk.ac.aber.Blockmation.FileManager;
import uk.ac.aber.Blockmation.MovieModel;
import uk.ac.aber.Blockmation.OurFileChooser;
import uk.ac.aber.Blockmation.Viewer;

/**
 * 
 * @author tom, aron
 */

public class ActionViewerLoadProject extends AbstractAction {
	
    private Viewer viewer;
    
    private File projectFile;
    private OurFileChooser ourFileChooser;
    MovieModel loaded;

    public ActionViewerLoadProject(Viewer viewer) {
        super("Load Project");    
        this.viewer = viewer;
        
        // the below from settings class file or?!
        //putValue(SHORT_DESCRIPTION, tooltip);  // Will appear as tooltip text.
        //putValue(MNEMONIC_KEY, new Integer(mnemonic));
        
    }
        
    public void actionPerformed(ActionEvent e) {
        
        ourFileChooser = new OurFileChooser(viewer);
    	projectFile = ourFileChooser.loadProject();
    	loaded = new MovieModel();
        loaded = FileManager.loadMovie(projectFile);
        
        if (loaded == null) {
        	System.err.println("File coudn't be loaded.");
        	// inform the user 
        } else {
        	viewer.updateNewModel(loaded);
        }  	
    }

}

